Page({
  data: {
    currentDate: new Date().getTime(),
    dateLayerVisible: false,
    houseLayerVisible: false,
    houseList: [],
    houseName: '',
    houseId: '',
    name: '',
    visitDate: ''
  },
  openHouseLayer () {
    this.setData({ houseLayerVisible: true })
  },
  closeHouseLayer () {
    this.setData({ houseLayerVisible: false })
  },
  openDateLayer () {
    this.setData({ dateLayerVisible: true })
  },
  closeDateLayer () {
    this.setData({ dateLayerVisible: false })
  },
  // goPassport () {
  //   wx.reLaunch({
  //     url: '/visitor_pkg/pages/passport/index'
  //   })
  // },
  onShow () {
    this.getList()
  },
  // 获取房屋列表
  async getList () {
    const { data } = await wx.http.get('/house')
    console.log(data)
    this.setData({
      houseList: data
    })
  },
  // 选择房屋
  selectHouse (e) {
    console.log(e)
    this.setData({
      houseName: e.detail.name,
      houseId: e.detail.id
    })
  },
  // 选择日期
  confirmDate (e) {
    // const date = new Date(e.detail)
    this.setData({
      // appointment: date.toLocaleDateString('zh-CN').replaceAll('/', '-'),
      visitDate: wx.utils.formatDate(e.detail),
      dateLayerVisible: false
    })
  },
  async goPassport () {
    // eslint-disable-next-line no-unused-vars
    const { houseList, houseLayerVisible, dateLayerVisible, houseName, currentDate, __webviewId__, ...body } = this.data
    const { data } = await wx.http.post('/visitor', body)
    wx.utils.toast('添加访客成功')
    wx.reLaunch({
      url: '/visitor_pkg/pages/passport/index?id=' + data.id
    })
  }
})
